<?php

namespace app\admin\model;

use think\Model;


class Auditlog extends Model
{


    // 表名
    protected $name = 'user_auditlog';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = true;
    protected $updateTime = true;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'role_text',
        'audit_status_text'
    ];
    

    
    public function getRoleList()
    {
        return ['agent' => __('Role Agent'), 'companion' => __('Role Companion'), 'room' => __('Role Room')];
    }

    public function getAuditStatusList()
    {
        return ['待审核' => __('待审核'), '已审核' => __('已审核'), '已驳回' => __('已驳回')];
    }


    public function getRoleTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['role']) ? $data['role'] : '');
        $list = $this->getRoleList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAuditStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['audit_status']) ? $data['audit_status'] : '');
        $list = $this->getAuditStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function admin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'auditor', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
